﻿using AdminManager.Permissions;
using AdminManager.System.SecurityLogs;
using Microsoft.AspNetCore.Authorization;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
using Volo.Abp.Identity;

namespace AdminManager.System
{
    [Authorize(AdminManagerPermissions.SecurityLogs.Default)]
    public class SecurityLogsAppService : ApplicationService, ISecurityLogsAppService
    {
        private readonly IIdentitySecurityLogRepository _identitySecurityLogRepository;

        public SecurityLogsAppService(IIdentitySecurityLogRepository identitySecurityLogRepository)
        {
            this._identitySecurityLogRepository = identitySecurityLogRepository;
        }
        public async Task<PagedResultDto<SecurityLogsDto>> GetListAsync(SecurityLogsSearchDto auditLogsInputDto)
        {

            var list = await this._identitySecurityLogRepository.GetListAsync(auditLogsInputDto.Sorting,
                auditLogsInputDto.MaxResultCount, auditLogsInputDto.SkipCount-1, auditLogsInputDto.startTime,
                auditLogsInputDto.endTime,null,null,null,null,auditLogsInputDto.userName);
            var totalCount = await this._identitySecurityLogRepository.GetCountAsync(auditLogsInputDto.startTime,
                auditLogsInputDto.endTime,null,null,null,null,auditLogsInputDto.userName);
            return new PagedResultDto<SecurityLogsDto>(totalCount, ObjectMapper.Map<List<IdentitySecurityLog>, List<SecurityLogsDto>>(list));
        }
    }
}
